import java.util.Stack;

/**
 * @Author ZhangCuirong
 * @Date 2025/9/8 9:11
 * @description:
 */
public class Solution7 {
    public int reverse(int x) {
        int res = 0;
        while (x != 0) {
            int temp = x % 10;
            if (res > 214748364 || res == 214748364 && temp > 7) {
                return 0;
            }
            if (res < -214748364 || res == -214748364 && temp < -8) {
                return 0;
            }
            res = res * 10 + temp;
            x /= 10;
        }
        return res;
    }

    public static void main(String[] args) {
        Solution7 solution = new Solution7();
        System.out.println(solution.reverse(123));
        System.out.println(solution.reverse(1534236469));
        System.out.println(solution.reverse(-2147483648));
        System.out.println(solution.reverse(-1563847412));
    }
}
